/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Dao;

import Pojo.Middlename;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author knyazev_o
 */
public class DaoMiddleName implements Interface.InterfaceMiddleName{

    @Override
    public boolean register(Session session, Middlename middleName) throws Exception {
        session.save(middleName);        
        return true;
    }

    @Override
    public List<Middlename> getAll(Session session) throws Exception {
        String hql="from Middlename";
        Query query=session.createQuery(hql);        
        List<Middlename> listMiddleName =(List<Middlename>) query.list();        
        return listMiddleName;
    }

    @Override
    public Middlename selectMiddleName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }
        Middlename middleName=(Middlename) query.uniqueResult();        
        return middleName;
    }

    @Override
    public List<Middlename> selectListMiddleName(Session session, String hql, List<Object> param) throws Exception {
        Query query=session.createQuery(hql);
        for(Object inParam:param){
            query.setParameter(param.indexOf(inParam), inParam);
        }       
        List<Middlename> listMiddleName =(List<Middlename>) query.list();        
        return listMiddleName;
    }

    @Override
    public boolean update(Session session, Middlename middleName) throws Exception {
        session.update(middleName);
        return true;
    }

    @Override
    public boolean delete(Session session, Middlename middleName) throws Exception {
        session.delete(middleName);
        return true;
    }
    
    
    
}
